#include <iostream>
#include <cctype>
#include <string>
using namespace std;

typedef unsigned long Item;

class Stack
{
	private:
		enum{MAX=10};
		Item *pitems;//holds stack items
		int size;//number of elements in stack
		int top;//indexm for top stack item
	public:
		Stack(int n=MAX);
		Stack(const Stack &st);
		~Stack();
		bool isempty()const;
		bool isfull()const;
		bool push(const Item& item);
		bool pop(Item &item);
		Stack & operator=(const Stack &st);
};

Stack::Stack(int n)
{
	this->pitems=new Item[n];
	this->size=n;
	this->top=0;
}

Stack::Stack(const Stack &st)
{
	this->pitems=new Item[st.size];
	this->size=st.size;
	this->top=0;
}

Stack::~Stack()
{
	delete [] this->pitems;
	this->pitems=NULL;
}

bool Stack::isempty()const
{
	return top==0;
}

bool Stack::isfull()const
{
	return top==MAX;
}

bool Stack::push(const Item &item)
{
	if(top<MAX)
	{
		this->pitems[top++]=item;
		return true;
	}
	else {
		return false;
	}
}

bool Stack::pop(Item &item)
{
	if(top>0)
	{
		item=this->pitems[--top];
		return true;
	}
	else {
		return false;
	}
}

Stack& Stack::operator=(const Stack &st)
{
	if(this==&st){
		return *this;
	}
	delete []this->pitems;
	this->pitems=new Item[st.size];
	this->top=0;
	this->size=st.size;
	return *this;
}

int main()
{
	Stack st;
	char ch;
	unsigned long po;
	cout<<"Please enter A to add a purchase order.\n"
		<<"P to process a PO, or Q to quit.\n";
	while(cin>>ch&&toupper(ch)!='Q')
	{
		while (cin.get()!='\n') {
			continue;
		}
		if(!isalpha(ch))
		{
			cout<<'\a';
			continue;
		}
		switch (ch) {
			case 'A':
			case 'a':
				cout<<"Enter a PO number to add:\n";
				cin>>po;
				if(st.isfull())
					cout<<"stack already full\n";
				else{
					st.push(po);
				}
				break;
			case 'p':
			case 'P':if(st.isempty())
						cout<<"stack already empty\n";
				else{
					st.pop(po);
					cout<<"PO #"<<po<<" popped\n";
					break;
				} 
		}
		cout<<"Please enter A to add a purchase order.\n"
			<<"P to process a PO, or Q to quit.\n";
	}
	cout<<"Bye\n";
	return 0;
}
